<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('/index');
});
Route::get('/404', function () {
    return view('404');
});
Route::get('/welcome',function(){
    return view('test');
});
Route::get('/rili',function(){
    return view('admin.rili.index');
});
Route::get('/qd',function(){
    return view('admin.rili.qd');
});
Route::group(['prefix'=>'admin'],function(){
    Route::get('/login',"\App\Http\Controllers\LoginController@index");
    Route::post('/login',"\App\Http\Controllers\LoginController@login");
    Route::get('/logout',"\App\Http\Controllers\LoginController@logout");
    Route::group(['middleware'=>'auth:admin'],function(){
        //首页
        Route::get('/home',"\App\Http\Controllers\HomeController@index");
        //-------------------------------客户-------------------------------//
        Route::group(['middleware'=>'can:customer_manage'],function() {
            //客户首页
            Route::get('/customer', "\App\Http\Controllers\customerController@index");
            //线索创建
            Route::get('/contact/create', "\App\Http\Controllers\customerController@contact_create");
            //客户创建
            Route::get('/customer/create', "\App\Http\Controllers\customerController@create");
            Route::post('/customer', "\App\Http\Controllers\customerController@store");
            //客户编辑
            Route::get('/customer/{customer}/edit', "\App\Http\Controllers\customerController@edit");
            Route::post('/customer/update/{customer}', "\App\Http\Controllers\customerController@view_update")->where('id', '[0-9]+');
            Route::post('/customer/{uid}/update', "\App\Http\Controllers\customerController@update")->where('uid', '[0-9]+');

            //客户伪删除
            Route::get('/customer/{uid}/delete', "\App\Http\Controllers\customerController@delete");
            //客户重分配
            Route::get('/customer/translation', "\App\Http\Controllers\customerController@translation");
            //客户重分配逻辑
            Route::post('/customer/customer_Redistribution', "\App\Http\Controllers\customerController@customer_Redistribution");
            //数据
            //所有客户数据
            Route::get('/customers/data', "\App\Http\Controllers\customerController@data");
            //个人客户数据
            Route::get('/customer/{id}/data', "\App\Http\Controllers\customerController@data2");
            //个人线索数据
            Route::get('/lead/{id}/data', "\App\Http\Controllers\customerController@data3");
            //所有线索数据
            Route::get('/leads/data', "\App\Http\Controllers\customerController@data4");
            //个人客户联系人数据
            Route::get('/contact/{id}/data', "\App\Http\Controllers\customerController@data5");
        });
        //-------------------------------产品-------------------------------//
        Route::group(['middleware'=>'can:product_manage'],function() {
            //产品首页
            Route::get('/product', "\App\Http\Controllers\productController@index");
            Route::get('/product/show', "\App\Http\Controllers\productController@data");
            //产品编辑
            Route::get('/product/{id}/edit', "\App\Http\Controllers\productController@edit");
            Route::post('/product/{id}/update', "\App\Http\Controllers\productController@update");
            Route::post('/product', "\App\Http\Controllers\productController@store");
            //产品创建
            Route::get('/product/create', "\App\Http\Controllers\productController@create");
            Route::post('/product/store', "\App\Http\Controllers\productController@operation");
            Route::get('/product_type/create', "\App\Http\Controllers\productController@product_create");
            Route::post('/product_type', "\App\Http\Controllers\productController@product_store");
            //图片上传接口
            Route::post('/product/upload', "\App\Http\Controllers\productController@upload");
            //产品删除
            Route::get('/product/{uid}/delete', "\App\Http\Controllers\productController@delete");
            Route::get('/product/excel/export','ExcelController@export');
            Route::get('/excel/import','ExcelController@import');
        });
        //-------------------------------线索-------------------------------//
        Route::group(['middleware'=>'can:lead_manage'],function() {
            //线索创建
            Route::get('/leads/create', "\App\Http\Controllers\LeadController@create");
            Route::post('/leads', "\App\Http\Controllers\LeadController@store");
            //线索编辑
            Route::get('/leads/{contact}/edit', "\App\Http\Controllers\LeadController@edit");
            Route::post('/leads/update/{contact}', "\App\Http\Controllers\LeadController@store_edit");
            Route::post('/leads/{id}/update', "\App\Http\Controllers\LeadController@update")->where('id', '[0-9]+');
            //线索删除
            Route::get('/leads/{id}/delete', "\App\Http\Controllers\LeadController@delete")->where('id', '[0-9]+');;
            //线索批量删除
            Route::get('/leads/delete', "\App\Http\Controllers\LeadController@del");
            //仍回线索池
            Route::get('/leads/lead_roll', "\App\Http\Controllers\LeadController@lead_roll");
            //重分配线索
            Route::get('/leads/lead_translation', "\App\Http\Controllers\LeadController@translation");
            Route::post('/leads/translation', "\App\Http\Controllers\LeadController@lead_Redistribution");
            //线索转客户
            Route::get('/customer/{uid}/toCustomer', "\App\Http\Controllers\LeadController@lead_to_customer")->where('uid', '[0-9]+');;
            Route::post('/customer/{id}', "\App\Http\Controllers\LeadController@to_customer")->where('id', '[0-9]+');;
        });
        //-------------------------------商机-------------------------------//
        Route::group(['middleware'=>'can:business_manage'],function() {
            //商机首页
            Route::get('/business', "\App\Http\Controllers\BusinessController@index");
            Route::get('/business/data', "\App\Http\Controllers\BusinessController@data");
            //商机创建
            Route::get('/business/create', "\App\Http\Controllers\BusinessController@create");
            Route::post('/business', "\App\Http\Controllers\BusinessController@store");
            //商机编辑
            Route::get('/business/{business}/edit', "\App\Http\Controllers\BusinessController@edit");
            Route::post('/business/update/{business}', "\App\Http\Controllers\BusinessController@view_update");
            Route::post('/business/{id}/update', "\App\Http\Controllers\BusinessController@update")->where('id', '[0-9]+');;
            //商机删除
            Route::get('/business/{id}/delete', "\App\Http\Controllers\BusinessController@delete")->where('id', '[0-9]+');
            Route::get('/business/del', "\App\Http\Controllers\BusinessController@del")->where('id', '[0-9]+');;
        });
        //-------------------------------合同-------------------------------//
        Route::group(['middleware'=>'can:contract_manage'],function() {
            //合同首页
            Route::get('/contract', "\App\Http\Controllers\ContractController@index");
            Route::get('/contract/data', "\App\Http\Controllers\ContractController@data");
            //合同创建
            Route::get('/contract/create', "\App\Http\Controllers\ContractController@create");
            Route::post('/contract', "\App\Http\Controllers\ContractController@store");
            //合同编辑
            Route::get('/contract/{contract}/edit', "\App\Http\Controllers\ContractController@edit");
            Route::post('/contract/update/{contract}', "\App\Http\Controllers\ContractController@view_update");
            Route::post('/contract/{id}/update', "\App\Http\Controllers\ContractController@update")->where('id', '[0-9]+');;
            //合同删除
            Route::get('/contract/{id}/delete', "\App\Http\Controllers\ContractController@delete")->where('id', '[0-9]+');
            Route::get('/contract/del', "\App\Http\Controllers\ContractController@del")->where('id', '[0-9]+');;
        });
        //-------------------------------任务-------------------------------//
        Route::group(['middleware'=>'can:contract_manage'],function() {
            //任务首页
            Route::get('/task', "\App\Http\Controllers\TaskController@index");
            Route::get('/task/data', "\App\Http\Controllers\TaskController@data");
            //任务创建
            Route::get('/task/create', "\App\Http\Controllers\TaskController@create");
            Route::post('/task', "\App\Http\Controllers\TaskController@store");
            Route::get('/task_type/create', "\App\Http\Controllers\TaskController@Task_create");
            Route::post('/task_type', "\App\Http\Controllers\TaskController@Task_store");
            //任务编辑
            Route::get('/task/{task}/edit', "\App\Http\Controllers\TaskController@edit");
            Route::post('/task/update/{task}', "\App\Http\Controllers\TaskController@view_update");
            Route::post('/task/{id}/update', "\App\Http\Controllers\TaskController@update")->where('id', '[0-9]+');;
            //任务删除
            Route::get('/task/{id}/delete', "\App\Http\Controllers\TaskController@delete")->where('id', '[0-9]+');
            Route::get('/task/del', "\App\Http\Controllers\TaskController@del")->where('id', '[0-9]+');;
        });
        //-------------------------------通讯簿-------------------------------//
        Route::group(['middleware'=>'can:user_manage'],function() {
            //用户列表
            Route::get('/user', "\App\Http\Controllers\AddressBookController@index");
            //用户数据接口
            Route::get('/user/show', "\App\Http\Controllers\AddressBookController@data");
            Route::post('/user/upload', "\App\Http\Controllers\AddressBookController@upload");
            //用户创建
            Route::get('/user/create', "\App\Http\Controllers\AddressBookController@create");
            Route::post('/user', "\App\Http\Controllers\AddressBookController@store");
            //用户编辑
            Route::get('/user/{admin_user}/edit', "\App\Http\Controllers\AddressBookController@edit");
            Route::post('/user/update/{admin_user}', "\App\Http\Controllers\AddressBookController@edit_view");

            Route::post('/user/{id}/update', "\App\Http\Controllers\AddressBookController@update")->where('id', '[0-9]+');;
            Route::get('/user/Edit_password', "\App\Http\Controllers\AddressBookController@Edit_password");
            Route::post('/user/store_password', "\App\Http\Controllers\AddressBookController@store_password");
            Route::get('/user/Edit_pwd', "\App\Http\Controllers\AddressBookController@Edit_pwd");
            Route::post('/user/store_pwd/{adminUser}', "\App\Http\Controllers\AddressBookController@store_pwd");
            //用户删除
            Route::get('/user/{id}/delete', "\App\Http\Controllers\AddressBookController@delete")->where('id', '[0-9]+');;
            Route::get('/user/del', "\App\Http\Controllers\AddressBookController@del");
            //用户测试列表
            Route::get('/user/test', "\App\Http\Controllers\AddressBookController@test");
        });
        //-------------------------------资料展示-------------------------------//
        Route::get('/user/{admin_user}/setting', "\App\Http\Controllers\AddressBookController@setting");
        Route::get('/product/{product}/setting', "\App\Http\Controllers\ProductController@setting");
        Route::get('/business/{business}/setting', "\App\Http\Controllers\BusinessController@setting");
        Route::get('/customer/{customer}/setting', "\App\Http\Controllers\CustomerController@setting");
        Route::get('/task/{task}/setting', "\App\Http\Controllers\TaskController@setting");
        Route::get('/contact/{contact}/setting', "\App\Http\Controllers\LeadController@setting");
        Route::get('/contract/{contract}/setting', "\App\Http\Controllers\ContractController@setting");
        //-------------------------------权限管理-------------------------------//
        //用户跟角色的行为
        Route::get('/users/{user}/role', '\App\Http\Controllers\AddressBookController@role');
        Route::post('/users/{user}/role', '\App\Http\Controllers\AddressBookController@storeRole');

         Route::group(['middleware'=>'can:user_manage'],function(){
             // 角色管理
             Route::get('/roles', '\App\Http\Controllers\RoleController@index');
             Route::get('/roles/create', '\App\Http\Controllers\RoleController@create');

             //操作行为
             Route::post('/roles/store', '\App\Http\Controllers\RoleController@store');
             //角色和用户

             Route::get('/roles/{role}/permission', '\App\Http\Controllers\RoleController@permission');
             Route::post('/roles/{role}/permission', '\App\Http\Controllers\RoleController@storePermission');

             // 权限管理
             Route::get('/permissions', '\App\Http\Controllers\PermissionController@index');
             Route::get('/permissions/create', '\App\Http\Controllers\PermissionController@create');
             Route::post('/permissions/store', '\App\Http\Controllers\PermissionController@store');
             Route::get('/permissions/{adminPermission}/update', '\App\Http\Controllers\PermissionController@edit');
             Route::post('/permissions/update/{adminPermission}', '\App\Http\Controllers\PermissionController@update');
         });
        //-------------------------------通知管理-------------------------------//
        //任务首页
        Route::get('/notice', "\App\Http\Controllers\NoticeController@index");
        Route::get('/notice_list', "\App\Http\Controllers\NoticeController@notice_list");
        //任务创建
        Route::get('/notices/create', "\App\Http\Controllers\NoticeController@create");
        Route::post('/notice', "\App\Http\Controllers\NoticeController@store");
        //任务编辑
        Route::get('/notice/{notice}/edit', "\App\Http\Controllers\NoticeController@edit");
        Route::post('/notice/update/{notice}', "\App\Http\Controllers\NoticeController@update");
        //任务删除
        Route::get('/notice/{id}/delete', "\App\Http\Controllers\NoticeController@delete")->where('id', '[0-9]+');
        Route::get('/notice/del', "\App\Http\Controllers\NoticeController@del")->where('id', '[0-9]+');;
    });

});